package com.example.springbootdemo.controller;

import com.example.springbootdemo.repository.UserRepository;
import com.example.springbootdemo.ojop.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class HelloController {

    @Autowired
    private UserRepository userRepository;

    public HelloController(){

    }

    @GetMapping("/hello")
    public String hello(){
        return "hello1";
    }

    @GetMapping("/{userId}")
    public User getUser(@PathVariable("userId") Integer userId){
        return this.userRepository.getById(userId);
    };

}
